package cn.ejopenai.core;

import cn.ejopenai.domain.MessageObject;

import java.util.ArrayList;
import java.util.List;

/**
 * author ： willie
 * 请求
 */
public class RequestHandler {
    private String requestMethod = "POST";                                  // 请求方式
    private String model="gpt-3.5-turbo";                                   // 使用的模型
    private static List<MessageObject> historyMsg = new ArrayList<>();      // 历史会话记录
    private String user = "user";                                           // 用户标识 "system"、"user" 或 "assistant"
    private int max_tokens = 50;                                            // 最大响应 token
    private boolean isInit;                                                 // 是否自行初始化

    public RequestHandler setPrompt(String prompt){
        MessageObject messageObject;
        // 初始化操作
        if(historyMsg.size() > 0){
            messageObject = new MessageObject("user", prompt);
        }else{
            if (isInit) {
                messageObject = new MessageObject("system", prompt);
            }else {
                historyMsg.add(new MessageObject("system", "你是一个有用的AI客服，名称为小丽"));
                messageObject = new MessageObject("user", prompt);
            }
        }

        historyMsg.add(messageObject);
        return this;
    }

    public RequestHandler setInit(boolean init) {
        isInit = init;
        return this;
    }

    public RequestHandler setResultMessageObject(MessageObject msgObj){
        historyMsg.add(msgObj);
        return this;
    }

    public RequestHandler setRequestMethod(String method){
        this.requestMethod = method;
        return this;
    }

    public RequestHandler setMaxTokens(int maxTokens){
        this.max_tokens = maxTokens;
        return this;
    }



    public RequestHandler setModel(String model){
        this.model = model;
        return this;
    }

    public RequestHandler setUser(String user){
        this.user = user;
        return this;
    }



    public String getRequestMethod() {
        return this.requestMethod;
    }

    public String getModel() {
        return model;
    }

    public List<MessageObject> getHistoryMsg() {
        return historyMsg;
    }

    public void setHistoryMsg(List<MessageObject> historyMsg) {
        this.historyMsg = historyMsg;
    }

    public String getUser() {
        return user;
    }

    public int getMaxTokens(){
        return this.max_tokens;
    }
}
